RSSTR = {
    'black': 0,
    'brown': 1,
    'red': 2,
    'orange': 3,
    'yellow': 4,
    'green': 5,
    'blue': 6,
    'violet': 7,
    'grey': 8,
    'white': 9
}

TLRCD = {
    'grey' : '0.05%',
    'violet' : '0.1%',
    'blue': '0.25%',
    'green': '0.5%',
    'brown': '1%',
    'red': '2%',
    'gold': '5%',
    'silver': '10%',
}

def label(colors):
    value = (10 * RSSTR[colors[0]] + RSSTR[colors[1]]) * 10**RSSTR[colors[2]]
    if value >= 1e9:
        return str(int(value / 1e9)) + ' gigaohms'
    if value >= 1e6:
        return str(int(value / 1e6)) + ' megaohms'
    if value >= 1e3:
        return str(int(value / 1e3)) + ' kiloohms'
    return str(value) + ' ohms'

def resistor_label(colors):
    '''Translate resistor label with 1,4,5 colors'''
    if colors == ['black']:
        return '0 ohms'
    int_list = []
    for i in colors[:-1]:
        int_list.append(RSSTR[i])
    [*digit ,multi] = int_list
    value = ''
    for i in digit:
        value += str(i)
    value = int(value) * 10**multi
    
    if value >= 1e9:
        return str(value / 1e9).removesuffix('.0') + ' gigaohms ±' + TLRCD[colors[-1]]
    if value >= 1e6:
        return str(value / 1e6).removesuffix('.0') + ' megaohms ±' + TLRCD[colors[-1]]
    if value >= 1e3:
        return str(value / 1e3).removesuffix('.0') + ' kiloohms ±' + TLRCD[colors[-1]]
    return str(value) + ' ohms ±' + TLRCD[colors[-1]]
